package com.atguigu.gulimall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gulimall.product.entity.SpuImage;
import com.atguigu.gulimall.product.entity.SpuInfo;
import com.atguigu.gulimall.product.service.SpuImageService;
import com.atguigu.gulimall.product.service.SpuInfoService;
import com.atguigu.gulimall.product.vo.SpuSaveInfoVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author nicc
 * @version 1.0
 * @className SpuController
 * @description TODO
 * @date 2022-09-29 00:01
 */

@Api(tags = "spu接口")
@RequestMapping("/admin/product")
@RestController
public class SpuController {

    @Autowired
    private SpuInfoService spuInfoService;

    @Autowired
    private SpuImageService spuImageService;



    /**
     * 根据3级目录id分页获取spu信息
     * @param page
     * @param limit
     * @param category3Id
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result getSpuPage(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit,
                             @RequestParam("category3Id") Long category3Id){

        Page<SpuInfo> spuInfoPage = spuInfoService.getSpuPage(page, limit, category3Id);

        return Result.ok(spuInfoPage);
    }

    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuSaveInfoVo spuSaveInfoVo){

        spuInfoService.saveSpuInfo(spuSaveInfoVo);

        return Result.ok();
    }

    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageListBySpuId(@PathVariable("spuId") Long spuId){

        List<SpuImage> spuImages = spuImageService.spuImageListBySpuId(spuId);

        return Result.ok(spuImages);
    }

}